<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>递归函数求和</title>
</head>
<body>
    
    <script>

        function sum (num1,...nums) {
            if (nums.length === 0) return num1;
            return num1 + sum(...nums);
        }

        console.log(sum(1,2,3,4,5,6));

        // 一般方法

        function sum_common () {
            var total = 0;
            for (var i=0;i<arguments.length;i++) {
                total += arguments[i];
            }
            return total;
        }

        console.log(sum_common(1,2,3,4,5,6));

    </script>
</body>
</html>